package com.ruoyi.dl.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dl.domain.DlUserGame;
import com.ruoyi.dl.service.IDlUserGameService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代练等级Controller
 * 
 * @author ruoyi
 * @date 2021-01-04
 */
@Controller
@RequestMapping("/dl/game")
public class DlUserGameController extends BaseController
{
    private String prefix = "dl/game";

    @Autowired
    private IDlUserGameService dlUserGameService;

    @RequiresPermissions("dl:game:view")
    @GetMapping()
    public String game()
    {
        return prefix + "/game";
    }

    /**
     * 查询代练等级列表
     */
    @RequiresPermissions("dl:game:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlUserGame dlUserGame)
    {
        startPage();
        List<DlUserGame> list = dlUserGameService.selectDlUserGameList(dlUserGame);
        return getDataTable(list);
    }

    /**
     * 导出代练等级列表
     */
    @RequiresPermissions("dl:game:export")
    @Log(title = "代练等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlUserGame dlUserGame)
    {
        List<DlUserGame> list = dlUserGameService.selectDlUserGameList(dlUserGame);
        ExcelUtil<DlUserGame> util = new ExcelUtil<DlUserGame>(DlUserGame.class);
        return util.exportExcel(list, "game");
    }

    /**
     * 新增代练等级
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代练等级
     */
    @RequiresPermissions("dl:game:add")
    @Log(title = "代练等级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlUserGame dlUserGame)
    {
        return toAjax(dlUserGameService.insertDlUserGame(dlUserGame));
    }

    /**
     * 修改代练等级
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DlUserGame dlUserGame = dlUserGameService.selectDlUserGameById(id);
        mmap.put("dlUserGame", dlUserGame);
        return prefix + "/edit";
    }

    /**
     * 修改保存代练等级
     */
    @RequiresPermissions("dl:game:edit")
    @Log(title = "代练等级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlUserGame dlUserGame)
    {
        return toAjax(dlUserGameService.updateDlUserGame(dlUserGame));
    }

    /**
     * 删除代练等级
     */
    @RequiresPermissions("dl:game:remove")
    @Log(title = "代练等级", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dlUserGameService.deleteDlUserGameByIds(ids));
    }
}
